#!/bin/bash

# 切换到脚本所在目录
cd "$(dirname "$0")"

echo "================================================"
echo "    建党在线系统 - Docker 停止服务"
echo "================================================"
echo ""

# 检测 Docker Compose 命令
if command -v docker &> /dev/null && docker compose version &> /dev/null 2>&1; then
    DOCKER_COMPOSE="docker compose"
elif command -v docker-compose &> /dev/null; then
    DOCKER_COMPOSE="docker-compose"
else
    echo "❌ 错误: 未找到 Docker Compose"
    exit 1
fi

echo "🛑 正在停止服务..."
echo ""

$DOCKER_COMPOSE down

if [ $? -eq 0 ]; then
    echo ""
    echo "✅ 服务已停止"
    echo ""
else
    echo ""
    echo "❌ 停止失败"
    echo ""
    exit 1
fi

